import { jwtDecode } from 'jwt-decode'

export function decodeToken(token) {
  try {
    return jwtDecode(token)
  } catch (error) {
    return null
  }
}

export function isTokenExpired(token) {
  try {
    const decoded = jwtDecode(token)
    return decoded.exp < Date.now() / 1000
  } catch (error) {
    return true
  }
}

export function getTokenExpirationDate(token) {
  try {
    const decoded = jwtDecode(token)
    return new Date(decoded.exp * 1000)
  } catch (error) {
    return null
  }
}
